package com.vint.leetcode;

import com.vint.common.TreeNode;

public class Leetcode606 {
	public String tree2str(TreeNode t) {
		if (t == null) {
			return "";
		}

		StringBuilder sb = new StringBuilder();
		sb.append(t.val);

		if (t.right != null) {
			sb.append("(").append(tree2str(t.left)).append(")")
					.append("(").append(tree2str(t.right)).append(")");
		} else if (t.left != null) {
			sb.append("(").append(tree2str(t.left)).append(")");
		}

		return sb.toString();
	}
}
